<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>数组</title>
</head>
<body>
  <script>
    var arr = [
      {
        id: 0,
        name: '孙悟空',
        value: 100
      },
      {
        id: 1,
        name: '猪八戒',
        value: 70
      },
      {
        id: 2,
        name: '沙和尚',
        value: 40
      },
      {
        id: 3,
        name: '唐僧',
        value: 0
      },
      {
        id: 4,
        name: '白龙马',
        value: 60
      }
    ]

    // 1、请将数组中的每一个元素，按照value值从小到大排序
    var compare = function(newarr){
    	return function(obj1,obj2){
    		var var1=obj1[newarr];
    		var var2=obj2[newarr];
    		if(var1<var2){
    			return -1;
    		}
    		else{
    			return 0;
    		}
    	}
    }
    var newarr=arr.sort(compare('value'));
    console.log(newarr);
  </script>
</body>
</html>